﻿USE [ERP]
GO

/****** Object:  View [dbo].[dsc_NeReevMFIX]    Script Date: 03/30/2009 11:29:05 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[dsc_NeReevMFIX]
AS
/****** Script for SelectTopNRows command from SSMS  ******/ 
SELECT     *, b.IPCTotal[IPC], CAST((b.IPCT * [ValoareInventar]) / 100.00 AS DECIMAL(18, 2)) AS [ValReevaluata], CAST((b.IPCT * [ValoareInventar]) 
                                              / 100.00 AS DECIMAL(18, 2)) - [ValoareInventar] AS [DifConta]
                       FROM          (SELECT     '*' AS [<2003], DEN, NRINV, CAST(GRUPA AS VARCHAR) + '.' + CAST(SUBGRUPA AS VARCHAR) + '.' + CAST(CLASA AS VARCHAR) 
                                                                       + '.' + CAST(SUBCLASA AS VARCHAR) + ISNULL(FAMILIA, '') AS [Clasificare], CAST(LNI AS VARCHAR) + '.' + CAST(ANI AS VARCHAR) 
                                                                       + '/12.2003' AS [DataIntrarii], ANI, LNI, VALINV[ValoareInventar]
                                                 FROM         [a_act_MIX]
                                                 WHERE     CONS IN ( 'A') AND ANI <= 2003) t1 LEFT OUTER JOIN
                                              [dsc_IPC] b ON b.AnulMF * 100 + b.LunaMF = 2003 * 100 + 12
UNION
SELECT     *,b.IPCTotal[IPC], CAST((b.IPCT * [ValoareInventar]) / 100.00 AS DECIMAL(18, 2)) AS [ValReevaluata], CAST((b.IPCT * [ValoareInventar]) 
                                              / 100.00 AS DECIMAL(18, 2)) - [ValoareInventar] AS [DifConta]  FROM          
                                              (SELECT     '' AS [<2003], DEN, NRINV, CAST(GRUPA AS VARCHAR) + '.' + CAST(SUBGRUPA AS VARCHAR) + '.' + CAST(CLASA AS VARCHAR) 
                                                                       + '.' + CAST(SUBCLASA AS VARCHAR) + ISNULL(FAMILIA, '') AS [Clasificare], CAST(LNI AS VARCHAR) + '.' + CAST(ANI AS VARCHAR) 
                                                                       + '/' AS [DataIntrarii], ANI, LNI, VALINV[ValoareInventar]
                                                 FROM         [a_act_MIX]
                                                 WHERE    CONS IN ('A') AND ANI > 2003) t1 LEFT OUTER JOIN
                                              [dsc_IPC] b ON b.AnulMF * 100 + b.LunaMF = t1.ANI * 100 + t1.LNI

GO

